package com.clkj.tramcarlibrary.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.clkj.tramcarlibrary.R;
import com.clkj.tramcarlibrary.entity.ToNmShoumoDetail;

import java.util.List;

/**
 * Created by Administrator on 2017/2/16.
 */

public class ShoumoAdapter extends BaseAdapter {

    private Context context;
    private List<ToNmShoumoDetail> shoumoDetailList;

    public ShoumoAdapter(Context context, List<ToNmShoumoDetail> shoumoDetailList) {
        this.context = context;
        this.shoumoDetailList = shoumoDetailList;
    }

    @Override
    public int getCount() {
        return shoumoDetailList.size();
    }

    @Override
    public Object getItem(int position) {
        return shoumoDetailList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder myViewHolder = null;
        if (convertView == null) {
            myViewHolder = new MyViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_shoumo_layout, null);

            myViewHolder.tv_station = (TextView) convertView.findViewById(R.id.tv_station);
            myViewHolder.tv_first_time = (TextView) convertView.findViewById(R.id.tv_first_time);
            myViewHolder.tv_last_time = (TextView) convertView.findViewById(R.id.tv_last_time);

            convertView.setTag(myViewHolder);
        } else {
            myViewHolder = (MyViewHolder) convertView.getTag();
        }
        myViewHolder.tv_station.setText(shoumoDetailList.get(position).getStation_name());
        myViewHolder.tv_first_time.setText("首班车:" + shoumoDetailList.get(position).getFirst_time());
        myViewHolder.tv_last_time.setText("末班车:" + shoumoDetailList.get(position).getLast_time());
        return convertView;
    }

    private class MyViewHolder {
        private TextView tv_station;
        private TextView tv_first_time;
        private TextView tv_last_time;
    }
}
